var express = require('express')
var router = express.Router()

var User = require('../models/user')


/* 登录 */
router.route('/login').post((req, res) => {
    User.findOne({
        name:req.body.name,
        pass:req.body.pass,
    }, (err, data) => {
        if (err) {
         console.log(err);
         return
        }
        res.json({
            status: '200',
            result:data,
        })
        console.log(JSON.stringify(data))
    })
})

/* 注册 */
router.get('/reg',(req, res) => {
    User.insertMany({
        uname:req.body.uname,
        upwd:req.body.upwd,
        phone:req.body.phone,
        gender:req.body.gender,
    }, (err, data) => {
        if (err) {
            console.log(err);
            return
        }
        res.send({
        status: '200',
        result:'ok'
        })
    })
})

module.exports = router